package cn.stronglink.assetmanage.business.check.view.detail;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.adapter.DropDownAdapter;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.utils.SpinnerShowUtil;
import cn.stronglink.assetmanage.utils.ToastUtil;

/**
 * 入库验收详情页
 * Created by chencongcong on 2018/6/15.
 */

public class CheckDetailView {
    private Fragment fragment;
    @BindView(R.id.tv_check_asset_name)
    EditText tv_check_asset_name;
    @BindView(R.id.sp_check_location)
    Spinner sp_check_location;
    @BindView(R.id.tv_check_asset_no)
    TextView tv_check_asset_no;
    @BindView(R.id.sp_brand_name)
    Spinner sp_brand_name;
    @BindView(R.id.sp_check_asset_class)
    Spinner sp_check_asset_class;
    @BindView(R.id.tv_check_sn_no)
    TextView tv_check_sn_no;
    @BindView(R.id.tv_check_rfid_no)
    TextView tv_check_rfid_no;
    @BindView(R.id.iv_check_picture)
    ImageView iv_check_picture;
    @BindView(R.id.sp_check_model)
    Spinner sp_check_model;
    private Asset asset;

    public CheckDetailView(Fragment fragment, View view) {
        this.fragment = fragment;
        ButterKnife.bind(this, view);
        asset = new Asset();
    }

    public void setViewNoClickable() {
        tv_check_asset_name.setEnabled(false);
        sp_check_model.setEnabled(false);
        tv_check_asset_no.setEnabled(false);
        tv_check_sn_no.setEnabled(false);
        tv_check_rfid_no.setEnabled(false);
        sp_check_location.setEnabled(false);
        sp_brand_name.setEnabled(false);
        sp_check_asset_class.setEnabled(false);
    }


    public void setSpinnerData(String[] roomArr, String[] brandArr, String[] assetTypeArr) {
        if (roomArr != null) {
            DropDownAdapter roomAdapter = new DropDownAdapter(fragment.getActivity(),  Arrays.asList(roomArr));
            sp_check_location.setAdapter(roomAdapter);
        }
        if (brandArr != null) {
            DropDownAdapter brandAdapter = new DropDownAdapter(fragment.getActivity(),  Arrays.asList(brandArr));
            sp_brand_name.setAdapter(brandAdapter);
        }
        if (assetTypeArr != null) {
            DropDownAdapter assetTypeAdapter = new DropDownAdapter(fragment.getActivity(),  Arrays.asList(assetTypeArr));
            sp_check_asset_class.setAdapter(assetTypeAdapter);
        }

    }


    public void showAssetDetail(Asset asset, Bitmap bm) {
        tv_check_asset_name.setText(asset.getAssetName());
        tv_check_asset_no.setText(asset.getAssetNo());
        tv_check_sn_no.setText(asset.getSerialNo());
        tv_check_rfid_no.setText(asset.getRfidNo());
        SpinnerShowUtil.setSpinnerItemSelectedByValue(sp_check_location,asset.getRoomName());
        SpinnerShowUtil.setSpinnerItemSelectedByValue(sp_brand_name,asset.getBrandName());
        SpinnerShowUtil.setSpinnerItemSelectedByValue(sp_check_asset_class,asset.getTypeName());
        SpinnerShowUtil.setSpinnerItemSelectedByValue(sp_check_model,asset.getModelName());
        if (bm != null) {
            iv_check_picture.setImageBitmap(bm);
        }
    }



    public void startActivityForPicture(int requestCode) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //启动相机程序
        intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
        fragment.startActivityForResult(intent, requestCode);
    }


    public void showAssetPicture(Bitmap bitmap) {
        if (bitmap != null) {
            iv_check_picture.setImageBitmap(bitmap);
        } else {
            showToast("未获取到图片");
        }
    }

    public void showProgressDialog(String msg) {

    }

    public void hideProgressDialog() {

    }

    public void showToast(String msg) {
        ToastUtil.toastShort(msg);
    }

}
